package com.example.smartcity.ui.dashboard.Fragment;

import android.content.Intent;
import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.example.smartcity.MainActivity;
import com.example.smartcity.R;
import com.example.smartcity.ui.Adapter.groupListViewAdapter;
import com.example.smartcity.ui.dashboard.AddAccountGroup;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;


public class AccountMangerFragment extends Fragment {
    private ListView listView;
    private TextView addGroup;
    int index = 0;
    static ArrayList<ArrayList<String>> lists = new ArrayList<>();
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    public void setBack(View view){
        AccountMangerFragment.this.getActivity().finish();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_account_manger, container, false);
        listView = view.findViewById(R.id.listView);
        addGroup = view.findViewById(R.id.addGroup);
        initView();
        addGroup();
        return view;
    }
    public void addGroup(){
        addGroup.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(AccountMangerFragment.this.getContext(), AddAccountGroup.class));
            }
        });
    }
    public void initView(){
        index = lists.size();
        ViewGroup.LayoutParams params = listView.getLayoutParams();
        params.height = index * 740;
        listView.setLayoutParams(params);
        listView.setAdapter(new groupListViewAdapter(getContext(),R.layout.groupitemlayout,lists));

    }
    public void addMethod(String type,String AccountKind,String number){
        ArrayList<String> list = new ArrayList();
        list.add(type);
        list.add(AccountKind);
        list.add(number);
        lists.add(list);
    }

    @Override
    public void onResume() {
        super.onResume();
        initView();
    }
}